package com.example.getechredis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    //String type
    @RequestMapping("/setKey")
    public String set(){
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        Student student=new Student();
        student.setName("zs");
        student.setAge("18");
        redisTemplate.opsForValue().set("student",student);
        return "success";
    }

    @RequestMapping("/getKey")
    public Student get(){
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        Student student =(Student) redisTemplate.opsForValue().get("student");
        return student;
    }

    //TODO 这块还得查查
    //Hash
    @RequestMapping("/getHash")
    public String getHash(){
        Object o = redisTemplate.opsForHash().get("stu", "name");
        System.out.println("------"+o);
        return "success";
    }
}
